
package com.jf.cloud.live.controller.multishop;

import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.live.dto.LiveLogDTO;
import com.jf.cloud.live.model.LiveLog;
import com.jf.cloud.live.service.LiveLogService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import ma.glasnost.orika.MapperFacade;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 直播记录
 *
 * @author zz
 * @date 2022-08-17 17:09:05
 */
@RestController("multishopLiveLogController")
@RequestMapping("/m/live_log")
@Tag(name = "直播记录")
public class LiveLogController {

    @Autowired
    private LiveLogService liveLogService;

    @Autowired
    private MapperFacade mapperFacade;

    @GetMapping("/page")
    @Operation(summary = "获取直播记录列表" , description = "分页获取直播记录列表")
    public ServerResponseEntity<PageVO<LiveLog>> page(@Valid PageDTO pageDTO, @ParameterObject LiveLogDTO liveLogDTO) {
        PageVO<LiveLog> liveLogPage = liveLogService.page(pageDTO, liveLogDTO);
        return ServerResponseEntity.success(liveLogPage);
    }

    @GetMapping
    @Operation(summary = "获取直播记录" , description = "根据liveLogId获取直播记录")
    public ServerResponseEntity<LiveLog> getByLiveLogId(@ParameterObject @RequestParam Long liveLogId) {
        return ServerResponseEntity.success(liveLogService.getByLiveLogId(liveLogId));
    }

    @PostMapping
    @Operation(summary = "保存直播记录" , description = "保存直播记录")
    public ServerResponseEntity<Void> save(@Valid @RequestBody LiveLogDTO liveLogDTO) {
        LiveLog liveLog = mapperFacade.map(liveLogDTO, LiveLog.class);
        liveLog.setLiveLogId(null);
        liveLogService.save(liveLog);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary = "更新直播记录" , description = "更新直播记录")
    public ServerResponseEntity<Void> update(@Valid @RequestBody LiveLogDTO liveLogDTO) {
        LiveLog liveLog = mapperFacade.map(liveLogDTO, LiveLog.class);
        liveLogService.update(liveLog);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary = "删除直播记录" , description = "根据直播记录id删除直播记录")
    public ServerResponseEntity<Void> delete(@RequestParam Long liveLogId) {
        liveLogService.deleteById(liveLogId);
        return ServerResponseEntity.success();
    }
}
